#include "client.h"
#define  SERVER_ADDR  "127.0.0.1"
#define  SERVER_PORT  10086
Client::Client()
{
    sock_fd=socket(AF_INET,SOCK_STREAM,0);
    if(sock_fd == -1)
    {
       cout<<"创建套接字失败"<<endl;
       return;
    }
}

void Client::Connect_the_Server()//连接服务器
{
    int retval;
    struct sockaddr_in addr;
    addr.sin_family = AF_INET; //IPV4
    addr.sin_port=htons(SERVER_PORT);//端口号
    addr.sin_addr.s_addr=inet_addr(SERVER_ADDR);

    retval=connect(sock_fd, (struct sockaddr *)&addr, sizeof(addr));
    if(retval == -1)
    {
        perror("connect error");
        return;
    }
    else {
        cout<<"链接成功"<<endl;
        return;
    }

}

void Client::ClienttoServer(Menu &m)
{
    int retval;
    retval=send(sock_fd,&m,sizeof(m),0);
    if(retval == -1)
    {
        cout<<"发送数据失败"<<endl;
        return;
    }
}

Client::~Client()
{

    close(sock_fd);

}
